package com.project;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.ImageView;


/**
 * Displays images from an SD card.
 */
public class Gallery extends Activity {

	ImageView imageView;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
		photoPickerIntent.setType("image/*");
		startActivityForResult(photoPickerIntent, 1);
	}
	
	// Bitmap bytes have to be created via a direct memory copy of the bitmap
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK) {
			Uri chosenImageUri = data.getData();

			/*Intent intent = new Intent(this,Description.class);
			intent.putExtra(Description.IMAGE_URI, getRealPathFromURI(chosenImageUri));
			startActivity(intent);*/
			
			
			
//			if (chosenImageUri != null) {
//				Preview.setImageUri(chosenImageUri);
//				//RGB.setImageUri(chosenImageUri);
//				
//				//startActivity(new Intent(this,Preview.class));
//			} else {
//				Toast.makeText(Gallery.this, "There is error reading image URI!!", Toast.LENGTH_SHORT).show();
//			}
		}
	}
	
	public String getRealPathFromURI(Uri contentUri) {
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(contentUri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }
}